package com.ibeeking.gmc.global.api.feign.fallback;

import com.ibeeking.gmc.global.api.common.query.AreaQuery;
import com.ibeeking.gmc.global.api.feign.GlobalDictFeignClient;
import com.ibeeking.found.common.entity.AreaDTO;
import com.ibeeking.found.common.entity.DictDTO;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

/**
 * 降级工场
 *
 * @Author ibeeking
 * @date 2019/1/18
 */
@Component
public class GlobalDictFeignFallbackFactory implements FallbackFactory<GlobalDictFeignClient> {
    @Override
    public GlobalDictFeignClient create(Throwable throwable) {
        return new GlobalDictFeignClient() {

            @Override
            public ResponseResult<List<DictDTO>> queryDictByTypes(String[] dictTypes) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，批量查询字典列表失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<DictDTO>> queryDictByType(String dictType) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询字典列表失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<DictDTO>> queryDictLables(Map<String, String> paramMap) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，批量查询字典标签失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<DictDTO> queryDictLable(String dictType, String dictValue) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询字典标签失败。");
            }

            @Override
            public ResponseResult<AreaDTO> queryName(String code) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询地区信息失败。");
            }

            @Override
            public ResponseResult<List<AreaDTO>> queryNames(List<String> codes) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询地区信息失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<AreaDTO>> queryArea(AreaQuery areaQuery) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询地区信息失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<List<AreaDTO>> queryAreasByparentCode(String parentCode) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询地区信息失败。", Collections3.emptyList());
            }

            @Override
            public ResponseResult<AreaDTO> queryAreaName(@NotBlank(message = "id不能为空") Long id) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询地区信息失败。");
            }

            @Override
            public ResponseResult<List<AreaDTO>> queryLowerAreasByCode(List<String> codes, Boolean flag) {
                return ResponseResult.fail(ResponseCodeEnum.SYSTEM_ERROR.getCode(), "进入降级工厂，查询地区信息失败。");
            }
        };
    }
}
